// import ReactDOM from 'react-dom';
import React from 'react'

import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx'
import { Modal, ActionSheet, Checkbox, SearchBar, Icon, List, Bubble, Tools, ActivityIndicator, Result } from 'weaver-mobile';
import { ListPage, RouteLayout, Form, ListViewPage } from 'weaver-mobile-page';
import { Route, withRouter } from 'react-router-dom'
import BatcgEdit from './BatchEdit'
import { forwardViewForm } from '../../util/common';
const AgreeItem = Checkbox.AgreeItem;
const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;

@inject("wfAgentStore")
@inject("wfSearchPageStore")
@withRouter
@observer
export default class AgentList extends React.Component {
    componentWillMount() {
        const { location } = this.props;
        const { setInitDatas,  getPageTitle } = this.props.wfAgentStore;
        const { pathname = "" } = location;
        let placeholder = "";
        getPageTitle(pathname);//更改头部
        switch (location.pathname) {
            case "/agent/mineAgentSet":
                placeholder = getLabel(391118, "请输入路径名称/代理人");
                break;
            case "/agent/hadAgented":
                placeholder = getLabel(391119, "请输入流程标题");
                break;
            case "/agent/toOthersAgent":
                placeholder = getLabel(391119, "请输入流程标题");
                break;
            case "/agent/all":
                placeholder = getLabel(9391123, "请输入路径名称/被代理人/代理人");
                break;
            default:
        }
        setInitDatas({
            placeholder: placeholder,
            propsVisiable: false,
            // isShowLoading: true
        });
    }

    componentWillUpdate() {
        const { location, wfAgentStore } = this.props;
        const { getPageTitle } = wfAgentStore;
        const { pathname = "" } = location;
        getPageTitle(pathname);
    }

    componentWillUnmount() {
        const { setInitDatas } = this.props.wfAgentStore;
        setInitDatas({ isShowCheck: false, selectedRowKeys: [], isSelectedAll: false })
    }

    //我的代理设置、全部
    getListDom1_back = (pathname) => {
        const { initDatas } = this.props.wfAgentStore;
        const { isShowCheck, selectedRowKeys, checkDatas, datasTab0, datasTab3 } = initDatas;

        let newDatas = [];
        if (pathname === "/agent/mineAgentSet") {
            newDatas = toJS(datasTab0);
        } else if (pathname === "/agent/all") {
            newDatas = toJS(datasTab3);
        }
        const items = [];
        for (let i = 0; i < newDatas.length; i++) {
            const template = {
                default: [
                    {
                        key: 'col1',
                        configs: [
                            {
                                key: 'col1_row1',
                                configs: [
                                    {
                                        key: 'workflowname',
                                        style: { fontWeight: "normal" }
                                    },
                                    {
                                        key: 'agenttypespan',
                                        className: "agenttypespan-left-set",
                                    },
                                ],
                            },
                            {
                                key: 'col1_row2',
                                configs: [
                                    {
                                        key: 'dataSpan',
                                        className: "color-gray"
                                    },
                                    {
                                        key: 'beginDate',
                                        className: "color-gray"
                                    },
                                    {
                                        key: "depart",
                                        className: "color-gray"
                                    },
                                    {
                                        key: 'endDate',
                                        className: "color-gray"
                                    },
                                ],
                            },
                            {
                                key: 'col1_row3',
                                configs: [
                                    {
                                        key: 'agenteridspan',
                                        className: "color-gray"
                                    },
                                ],
                            },
                        ],
                    },
                ],
            };
            let isDisabled = (checkDatas.length === newDatas.length) && toJS(checkDatas)[i].randomFieldCk === "false" && isShowCheck;
            items.push(<ListPage.Item
                key={newDatas[i].id}
                data={newDatas[i]}
                template={template}
                showCheck={isShowCheck}
                disabled={isDisabled && true}
                checked={toJS(selectedRowKeys).includes(newDatas[i].id)}
                swipeActionProps={{
                    style: { backgroundColor: 'gray' },
                    autoClose: true,
                    right: [
                        {
                            text: getLabel(93, '编辑'),
                            className: "bianji",
                            onPress: () => { this.editAgent(newDatas[i]) },
                        },
                        {
                            text: getLabel(391120, '收回代理'),
                            className: "shouhui",
                            onPress: () => { this.tackBackAgent(newDatas[i]) },
                        },
                    ]
                }}
                withSwipeAction={(checkDatas.length === newDatas.length) && toJS(checkDatas)[i].randomFieldCk === "true" && true}
                onSelect={() => { this.onSelectAgent(newDatas[i], isDisabled) }}
                onClick={() => { this.onSelectAgent(newDatas[i], isDisabled) }}
            >
            </ListPage.Item>)
        }
        if (items.length > 0) {
            return <div className={isShowCheck ? "wf-agent-agentList wf-agent-height-131 " : "wf-agent-agentList wf-agent-height-90 "}>
                <List >
                    {items}
                </List>
            </div>;
        } else {//暂无数据
            return (this.getNoDataPage())
        }
    }

    //////////////////////////为了满足滚动刷新需要
    getTemplate1 = (template) => {
        const newTemp = {
            // ...template,
            default: [{
                key: 'col_1',
                render: (data) => {
                    let { workflowname, agenttypespan, beagenteridspan, beginDate, beginDatespan = "", endDatespan = "", endDate, agenteridspan } = data;
                    if (beginDate === "1900-01-01") { beginDate = getLabel(763, "不限") }
                    if (endDate === "2099-12-31" || endDate === "2100-01-01") { endDate = getLabel(763, "不限") }
                    if (beginDatespan) {
                        beginDate = beginDatespan;
                    }
                    if (endDatespan) {
                        endDate = endDatespan;
                    }
                    return (
                        <div>
                            <div style={{ display: "flex" }}>
                                <div style={{ flex: "10", wordBreak: "break-all", color: "#333333" }}>
                                    {workflowname}
                                </div>
                                <div style={{ flex: "2" }} ><div style={{ position: "absolute", right: "10px", top: "10px" }} dangerouslySetInnerHTML={{ __html: agenttypespan }}></div></div>
                            </div>
                            <div style={{ color: "#999999", display: "flex" }}>
                                <div style={{ flex: "10", wordBreak: "break-all" }}>
                                    {getLabel(391121, "代理起止时间") + "：" + beginDate + "~" + endDate}
                                </div>
                                <div style={{ flex: "2" }}></div>
                            </div>
                            <div style={{ color: "#999999" }}>
                                {beagenteridspan && <span >{getLabel(17565, "被代理人") + `：` + beagenteridspan}</span>}
                                <span style={{ marginLeft: beagenteridspan ? "20px" : "0" }}>{agenteridspan}</span>
                            </div>
                        </div>
                    );
                },
            }],
        };
        return newTemp;
    }

    getRowProps1 = (rowData) => {
        const { isShowCheck } = this.props.wfAgentStore.initDatas;
        let withSwipeAction = true;
        let disabled = false;
        if (rowData.randomFieldOp) {
            let checkData = JSON.parse(rowData.randomFieldOp);
            if (isShowCheck) {
                withSwipeAction = false;
            } else {
                if (checkData[0] === false && checkData[1] === false) {
                    withSwipeAction = false;
                } else {
                    if (checkData.indexOf(true) > -1) {//显示
                        withSwipeAction = true;
                    } else {//不显示
                        withSwipeAction = false;
                    }
                }
            }
        }
        if (rowData.randomFieldCk) {
            if (rowData.randomFieldCk === "false") {
                disabled = true;
            }
        }
        return {
            withSwipeAction: withSwipeAction,
            disabled: disabled,
        }
    }

    getListDom1 = () => {
        const { wfAgentStore } = this.props;
        const { initDatas } = wfAgentStore;
        const { listViewPage_listsotre14, isShowCheck } = initDatas;
        // if (listViewPage_listsotre14.data.length > 0) {
        //     return (
        //         <ListViewPage.Normal
        //             className="wf-agent-list-view-page"
        //             style={{ height: isShowCheck ? "calc(100% - 180px)" : "calc(100% - 85px)" }}
        //             showCheck={isShowCheck}
        //             store={listViewPage_listsotre14}
        //             withSwipeAction={!isShowCheck}
        //             rowKey="randomFieldId"
        //             swipeActionProps={
        //                 {
        //                     style: { backgroundColor: 'gray' },
        //                     autoClose: true,
        //                     right: [
        //                         {
        //                             text: '编辑',
        //                             className: "bianji",
        //                             onPress: (item) => { this.editAgent(item) },
        //                         },
        //                         {
        //                             text: '收回代理',
        //                             className: "shouhui",
        //                             onPress: (item) => { this.tackBackAgent(item) },
        //                         },
        //                     ]
        //                 }
        //             }
        //             getTemplate={this.getTemplate1}
        //             getRowProps={this.getRowProps1}
        //             onRowSelect={(selectedRowKeys) => {
        //                 this.onSelectAgent(selectedRowKeys)
        //             }}
        //         // onRowClick={rowData => console.log(rowData)}
        //         />
        //     );
        // } else {
        //     return (this.getNoDataPage())
        // }
        // if (listViewPage_listsotre14.hasMore) {//数据请求完毕
        //     console.log(14)
        // }
        if (!listViewPage_listsotre14.hasMore) {
            if (listViewPage_listsotre14.data.length === 0) {
                return this.getNoDataPage();
            } else {
                return (
                    <ListViewPage.Normal
                        className="wf-agent-list-view-page"
                        style={{ height: isShowCheck ? "calc(100% - 180px)" : "calc(100% - 85px)" }}
                        showCheck={isShowCheck}
                        store={listViewPage_listsotre14}
                        withSwipeAction={!isShowCheck}
                        rowKey="randomFieldId"
                        swipeActionProps={
                            {
                                style: { backgroundColor: 'gray' },
                                autoClose: true,
                                right: [
                                    {
                                        text: getLabel(93, '编辑'),
                                        className: "bianji",
                                        onPress: (item) => { this.editAgent(item) },
                                    },
                                    {
                                        text: getLabel(391120, '收回代理'),
                                        className: "shouhui",
                                        onPress: (item) => { this.tackBackAgent(item) },
                                    },
                                ]
                            }
                        }
                        getTemplate={this.getTemplate1}
                        getRowProps={this.getRowProps1}
                        onRowSelect={(selectedRowKeys) => {
                            this.onSelectAgent(selectedRowKeys)
                        }}
                    />
                );

            }
        } else {
            return (
                <ListViewPage.Normal
                    className="wf-agent-list-view-page"
                    style={{ height: isShowCheck ? "calc(100% - 180px)" : "calc(100% - 85px)" }}
                    showCheck={isShowCheck}
                    store={listViewPage_listsotre14}
                    withSwipeAction={!isShowCheck}
                    rowKey="randomFieldId"
                    swipeActionProps={
                        {
                            style: { backgroundColor: 'gray' },
                            autoClose: true,
                            right: [
                                {
                                    text: getLabel(93, '编辑'),
                                    className: "bianji",
                                    onPress: (item) => { this.editAgent(item) },
                                },
                                {
                                    text: getLabel(391120, '收回代理'),
                                    className: "shouhui",
                                    onPress: (item) => { this.tackBackAgent(item) },
                                },
                            ]
                        }
                    }
                    getTemplate={this.getTemplate1}
                    getRowProps={this.getRowProps1}
                    onRowSelect={(selectedRowKeys) => {
                        this.onSelectAgent(selectedRowKeys)
                    }}
                />
            );

        }

    }

    getTemplate2 = (template) => {
        const { location } = this.props;
        const newTemp = {
            // ...template,
            default: [{
                key: 'col_1',
                render: (data) => {
                    const { requestnamenewspan, agentorbyagentidspan, useridspan, workflowidspan, operatedatespan } = data;
                    return (
                        <div>
                            <div style={{ display: "flex" }}>
                                <div style={{ flex: "10", wordBreak: "break-all", color: "#333333" }}>
                                    <div dangerouslySetInnerHTML={{ __html: requestnamenewspan }}></div>
                                </div>
                            </div>
                            <div style={{ color: "#999999" }}>
                                {location.pathname === "/agent/hadAgented" ? getLabel(17565, "被代理人") + ' : ' + agentorbyagentidspan : getLabel(17566, '代理人') + ' : ' + useridspan}
                            </div>
                            <div style={{ color: "#999999" }}>
                                {getLabel(34067, "流程路径")}：{workflowidspan}
                            </div>
                            <div style={{ color: "#999999", wordBreak: "break-all" }}>
                                {getLabel(391122, "处理时间")}：{operatedatespan}
                            </div>
                        </div>
                    );
                },
            }],
        };
        return newTemp;
    }

    getListDom2 = () => {
        const { wfAgentStore } = this.props;
        const { initDatas } = wfAgentStore;
        const { listViewPage_listsotre23, isShowCheck } = initDatas;
        // if (listViewPage_listsotre23.data.length > 0) {
        //     return (
        //         <ListViewPage.Normal
        //             className="wf-agent-list-view-page"
        //             showCheck={isShowCheck}
        //             store={listViewPage_listsotre23}
        //             rowKey="randomFieldId"
        //             getTemplate={this.getTemplate2}
        //             onRowClick={(rowData) => {
        //                 this.openForm(rowData)
        //             }}
        //         />
        //     );
        // } else {
        //     return (this.getNoDataPage())
        // }
        if (!listViewPage_listsotre23.hasMore) {
            if (listViewPage_listsotre23.data.length === 0) {
                return this.getNoDataPage();
            } else {
                return (
                    <ListViewPage.Normal
                        className="wf-agent-list-view-page"
                        // style={{ height:"calc(100% - 85px)" }}
                        showCheck={isShowCheck}
                        store={listViewPage_listsotre23}
                        rowKey="randomFieldId"
                        getTemplate={this.getTemplate2}
                        onRowClick={(rowData) => {
                            this.openForm(rowData)
                        }}
                    />
                );
            }
        } else {
            return (
                <ListViewPage.Normal
                    className="wf-agent-list-view-page"
                    // style={{ height: "calc(100% - 85px)" }}
                    showCheck={isShowCheck}
                    store={listViewPage_listsotre23}
                    rowKey="randomFieldId"
                    getTemplate={this.getTemplate2}
                    onRowClick={(rowData) => {
                        this.openForm(rowData)
                    }}
                />
            );
        }
    }

    //////////////////////////为了满足滚动刷新需要
    getNoDataPage = () => {
        return (
            <div style={{ width: "100%", height: "100%" }} className="wf-agent-NoData">
                <Result
                    img={<Icon type="no-data" size="lg" />}
                    message={getLabel(83553, "暂无数据")}
                />
            </div>
        )
    }

    //我代理的流程、交办他人的流程
    getListDom2_back = (pathname) => {
        const { location, wfAgentStore } = this.props;
        const { initDatas } = wfAgentStore;
        const { isShowCheck, selectedRowKeys, datasTab1, datasTab2 } = initDatas;
        let newDatas = [];
        if (pathname === "/agent/hadAgented") {
            newDatas = toJS(datasTab1);
        } else if (pathname === "/agent/toOthersAgent") {
            newDatas = toJS(datasTab2);
        }
        const items = [];
        newDatas.map(item => {
            if (location.pathname === "/agent/hadAgented") {//我代理的流程
                item.agenteridspanlabel = getLabel(17565, "被代理人") + "：";
            } else if (location.pathname === "/agent/toOthersAgent") {//交办他人的代理
                item.agenteridspanlabel = getLabel(17566, '代理人') + "：";
            }
            item.dealtimelabel = getLabel(391122, "处理时间") + "：";
            item.workflowidspanlabel = getLabel(34067, "流程路径") + "：";
            item.workflowidspan = '[' + item.workflowidspan + ']';
            const template = {
                default: [
                    {
                        key: 'col1',
                        configs: [
                            {
                                key: 'col1_row1',
                                configs: [
                                    {
                                        key: 'requestnamenewspan',
                                        style: {
                                            fontWeight: "normal"
                                        }
                                    },
                                ],
                            },
                            {
                                key: 'col1_row2',
                                configs: [
                                    {
                                        key: 'agenteridspanlabel',
                                        className: "color-gray"
                                    },
                                    {
                                        key: location.pathname === "/agent/hadAgented" ? 'agentorbyagentidspan' : "useridspan",
                                        className: "color-gray"
                                    },
                                ],
                            },
                            {
                                key: 'col1_row3',
                                configs: [
                                    {
                                        key: 'workflowidspanlabel',
                                        className: "color-gray"
                                    },
                                    {
                                        key: 'workflowidspan',
                                        className: "color-gray"
                                    },
                                ],
                            },
                            {
                                key: 'col1_row4',
                                configs: [
                                    {
                                        key: 'dealtimelabel',
                                        className: "color-gray"
                                    },
                                    {
                                        key: 'operatedatespan',
                                        className: "color-gray"
                                    },
                                ],
                            },
                        ],
                    },
                ],
            };
            items.push(<ListPage.Item
                key={item.id}
                data={item}
                template={template}
                showCheck={isShowCheck}
                disabled={isShowCheck && true}
                checked={toJS(selectedRowKeys).includes(item.id)}
                onSelect={() => { this.onSelectAgent(item) }}
                onClick={() => { this.openForm(item) }}
            >
            </ListPage.Item>)
            return items;
        })
        if (items.length > 0) {
            return <div className={isShowCheck ? "wf-agent-agentList wf-agent-height-131 " : "wf-agent-agentList wf-agent-height-90 "}>
                <List > {items} </List>
            </div>;
        } else {
            return (this.getNoDataPage())
        }
    }

    openForm = (item) => {
        const { location,wfAgentStore } = this.props;
        const { nowPath } = wfAgentStore;
        const { pathname } = location;
        let timestamp = Date.parse(new Date());
        const urlParams = {
            requestid: item.randomFieldId,
            _workflowid: item.workflowid,
            _workflowtype: "",
            // isovertime = "不知",
            preloadkey: timestamp,
            timestamp: timestamp,
        };
        if(pathname === '/agent/hadAgented'){
            urlParams.f_weaver_belongto_userid = item.userid;
            urlParams.f_weaver_belongto_usertype = item.usertype || '0';
        }else if(pathname === '/agent/toOthersAgent'){
            urlParams.f_weaver_belongto_userid = item.agentorbyagentid;
            urlParams.f_weaver_belongto_usertype = item.usertype || '0';
        }
        forwardViewForm(urlParams, nowPath);
    }

    onSelectAgent = (selectedRowKeys = []) => {
        const { setInitDatas } = this.props.wfAgentStore;
        let listViewPage_listsotre = this.getlistViewPage_listsotre()
        setInitDatas({ selectedRowKeys: selectedRowKeys })
        if (listViewPage_listsotre.data.length === selectedRowKeys.length) {
            setInitDatas({ isSelectedAll: true })
        } else {
            setInitDatas({ isSelectedAll: false })
        }
    }

    getlistViewPage_listsotre = () => {
        const { initDatas } = this.props.wfAgentStore;
        const { listViewPage_listsotre14, listViewPage_listsotre23 } = initDatas;
        let listViewPage_listsotre = listViewPage_listsotre14;
        if (this.props.location.pathname === "/agent/mineAgentSet" || this.props.location.pathname === "/agent/all") {//|| this.props.location.pathname === "/agent/mineAgentSet/batchEdit" || this.props.location.pathname === "/agent/all/batchEdit"{
            listViewPage_listsotre = listViewPage_listsotre14;
        } else if (this.props.location.pathname === "/agent/hadAgented" || this.props.location.pathname === "/agent/toOthersAgent") {
            listViewPage_listsotre = listViewPage_listsotre23;
        }
        return listViewPage_listsotre;
    }

    getGroupButton = () => {
        const { initDatas, setInitDatas, takeBackPromptMsg } = this.props.wfAgentStore;
        const { batchEditOrBatchReceive, selectedRowKeys, isSelectedAll, nowPath, checkDatas, layout_batchEdit } = initDatas;
        let listViewPage_listsotre = this.getlistViewPage_listsotre();
        let flag = false;//全部都不能选择
        let disabled = false;
        let newArr = [];
        toJS(listViewPage_listsotre.data).map(item => {
            if (item.randomFieldCk) {
                if (item.randomFieldCk === "true") {
                    newArr.push(item);
                }
            }
        })
        if (newArr.length === 0) {
            disabled = true;
        }
        return (
            <div className='wf-agent-addagent-group-button'>
                <ButtonGroup
                    data={[
                        {
                            key: 'selectAll',
                            text: <AgreeItem checked={isSelectedAll} disabled={disabled}>  {getLabel(556, "全选")}</AgreeItem>,
                            onClick: () => {
                                if (!disabled) {
                                    const { initDatas } = this.props.wfAgentStore;
                                    const { datasTab0, datasTab1, datasTab2, datasTab3 } = initDatas;
                                    let listViewPage_listsotre = this.getlistViewPage_listsotre();
                                    let datas = [];
                                    datas = toJS(listViewPage_listsotre.data);

                                    if (toJS(listViewPage_listsotre.selectedRowKeys).length === newArr.length) {
                                        setInitDatas({ selectedRowKeys: [], isSelectedAll: false })
                                        listViewPage_listsotre.selectedRowKeys = [];
                                    } else {
                                        let arr = [];
                                        newArr.map(item => {
                                            arr.push(item.randomFieldId)
                                        })
                                        setInitDatas({ selectedRowKeys: arr, isSelectedAll: true })
                                        listViewPage_listsotre.selectedRowKeys = arr;
                                    }
                                }
                            },
                            className: "wf-agent-button-allSelect",
                        }, {
                            key: 'submit',
                            text: batchEditOrBatchReceive ? getLabel(33243, "批量收回") : getLabel(383518, "批量编辑"),
                            onClick: () => {
                                if (batchEditOrBatchReceive) {//批量收回
                                    if (selectedRowKeys.length > 0) {
                                        let str = selectedRowKeys.join(",");
                                        takeBackPromptMsg({
                                            symbol: "it",
                                            agentid: str,
                                        }, (promptmsg) => { this.receiveAgent(0, promptmsg) })
                                    } else {
                                        Bubble.warning(getLabel(391125, '请选择需要收回的代理'), 2);
                                    }
                                } else {//批量编辑
                                    if (selectedRowKeys.length > 0) {
                                        if (toJS(selectedRowKeys).length > 0) {
                                            this.props.history.push(layout_batchEdit.path);
                                        }
                                    } else {
                                        Bubble.warning(getLabel(391126, '请选择需要编辑的代理'), 2);
                                    }
                                }

                            },
                            type: 'primary',
                        }]
                    }
                />
            </div>
        )
    }

    //确定(批量)收回代理
    onOk = (type, item) => {
        const { takeBackAgent, initDatas } = this.props.wfAgentStore;
        const { selectedRowKeys, radioChecked } = initDatas;
        let agentid = toJS(selectedRowKeys).join(",");

        let params = {};
        if (type === 0) {
            params = {
                symbol: "mt",
                agentid: agentid,
                backRunning: radioChecked ? 1 : 0,
            }
        } else if (type === 1) {
            params = {
                symbol: "it",
                agentid: item.id || item.randomFieldId,
                backRunning: radioChecked ? 1 : 0,
            }
        } else if (type === 2) {
            params = {
                agentid: item.id || item.randomFieldId,
                symbol: "pt",
                bagentuid: item.operatorid,
                backRunning: radioChecked ? 1 : 0,
            }
        }
        takeBackAgent(params);
    }

    //编辑代理
    editAgent = (item) => {
        const { getAgentDetail, setEditAgent } = this.props.wfAgentStore;
        let params = {
            agentid: item.id || item.randomFieldId,
            symbol: "edit",
        }
        setEditAgent({ ...params, parentPath: this.props.location.pathname })
        getAgentDetail(params);
        this.props.history.push('/agent/editAgent');
    }

    //收回代理 点击收回代理，弹出框选择【收回此条代理】【收回全部代理】
    tackBackAgent = (item) => {
        const { setInitDatas } = this.props.wfAgentStore;
        let hasAll = true;
        if (item.randomFieldOp) {
            hasAll = JSON.parse(item.randomFieldOp)[2];
        }
        const buttons1 = [
            {
                content: getLabel(391127, "收回此条代理"),
                onClick: () => {
                    const { takeBackPromptMsg } = this.props.wfAgentStore;
                    setInitDatas({ selectedRowKeys: [item.id] })
                    takeBackPromptMsg({
                        symbol: "it",
                        agentid: item.id
                    }, (promptmsg) => { this.receiveAgent(1, promptmsg, item) })

                }
            },
            {
                content: getLabel(391128, "收回全部代理"),
                onClick: () => {
                    const { initDatas, takeBackPromptMsg } = this.props.wfAgentStore;
                    const { datas } = initDatas;
                    takeBackPromptMsg({
                        agentid: item.id || item.randomFieldId,
                        symbol: "pt",
                        // bagentuid: item.operatorid,
                        bagentuid: item.randomField1,
                    }, (promptmsg) => { this.receiveAgent(2, promptmsg, item) })
                }
            },
            {
                content: getLabel(201, "取消"),
                onClick: () => { console && console.log("取消") }
            },
        ]
        const buttons2 = [
            {
                content: getLabel(391127, "收回此条代理"),
                onClick: () => {
                    const { takeBackPromptMsg } = this.props.wfAgentStore;
                    setInitDatas({ selectedRowKeys: [item.id] })
                    takeBackPromptMsg({
                        symbol: "it",
                        agentid: item.id
                    }, (promptmsg) => { this.receiveAgent(1, promptmsg, item) })

                }
            },
            {
                content: getLabel(201, "取消"),
                onClick: () => { console && console.log("取消") }
            },
        ]
        ActionSheet.showActionSheetWithOptions({
            options: hasAll ? buttons1 : buttons2,
            cancelButtonIndex: hasAll ? buttons1.length - 1 : buttons2.length - 1,
            maskClosable: true,
            onTouchStart: e => e.preventDefault(),
        })
    }

    receiveAgent = (type, promptmsg, item) => {
        const { setInitDatas, initDatas } = this.props.wfAgentStore;
        const { radioChecked } = this.props.wfAgentStore.initDatas;
        let content = "";
        if (type === 0) {

        }
        let chechbox = (
            <div className='wf-agent-addagent-receiveAgent' style={{}}>
                <AgreeItem
                    name="string"
                    defaultChecked
                    onChange={(e) => {
                        const { radioChecked } = this.props.wfAgentStore.initDatas;
                        setInitDatas({ radioChecked: !radioChecked })
                    }}
                ><span style={{ color: "red", fontSize: "13px" }}>{getLabel(383601, "收回流转中的流程代理")}</span></AgreeItem>
            </div>
        );
        Modal.alert(
            promptmsg,
            chechbox,
            [
                { text: getLabel(201, "取消"), onPress: () => { console && console.log("cancle") } },
                { text: getLabel(826, "确定"), onPress: () => { this.onOk(type, item) } },
            ])

    }

    render() {
        const { location } = this.props;
        const { initDatas, setAdvancedItem, layout, updateFormAdvanced, searchPage_layout, searchValue, reFreshDatas, advancedItem, fresh } = this.props.wfAgentStore;
        const { isShowCheck, isShowLoading, layout_batchEdit, isAdVancedHasData, searchParams } = initDatas;
        let listViewPage_listsotre = this.getlistViewPage_listsotre();
        const { form } = advancedItem;
        let placeholder = "";
        let ssStr = ""
        switch (location.pathname) {
            case "/agent/mineAgentSet": placeholder = getLabel(391118, "请输入路径名称/代理人"); ssStr = "mineAgentSet"; break;
            case "/agent/hadAgented": placeholder = getLabel(391119, "请输入流程标题"); ssStr = "hadAgented"; break;
            case "/agent/toOthersAgent": placeholder = getLabel(391119, "请输入流程标题"); ssStr = "toOthersAgent"; break;
            case "/agent/all": placeholder = getLabel(391123, "请输入路径名称/被代理人/代理人"); ssStr = "all"; break;
            default:
        }
        return (
            <div className="wf-agent-list-wrap">
                {isShowLoading && <ActivityIndicator
                    toast
                    text={getLabel(500408 , "加载中...")}
                    animating={isShowLoading}
                />}
                <div>
                    <SearchBar
                        className="search-select"
                        placeholder={placeholder}
                        value={searchValue}
                        showExtraButton
                        extraButton={[
                            { key: 'advanced', show: <Icon key={isAdVancedHasData ? "filter-o-hot" : "filter-o"} type={isAdVancedHasData ? "filter-o-hot" : "filter-o"} className={isAdVancedHasData && "color-blue"} /> },
                        ]}
                        onExtraButtonClick={(key) => {
                            if (key === "advanced") {
                                const { nowPath } = initDatas;
                                setAdvancedItem({ parentPath: nowPath })
                                if (this.props.location.pathname === "/agent/hadAgented" || this.props.location.pathname === "/agent/toOthersAgent") {
                                    let newForm = new Form.Store()
                                    newForm.initForm(advancedItem.conditioninfo, nowPath + '/advanceSearch');
                                    let newSearchParams = toJS(searchParams)
                                    newForm.updateFields({ ...newSearchParams, requestname: { value: searchValue } });
                                    setAdvancedItem({ form: newForm });
                                }
                                this.props.history.push(layout.path)
                            }
                        }}
                        onFocus={() => {
                            const { setState } = this.props.wfSearchPageStore
                            setState({ placeholder, ssName: ssStr, searchValue: searchValue })
                            this.props.history.push(searchPage_layout.path)
                        }}
                    />
                </div>
                <div style={{ height: "100%" }}>
                    {isShowCheck && <div className="wf-agent-list-selectedMsg" >
                        <span className="wf-agent-list-selectedMsg-cancel" onClick={() => {
                            const { setInitDatas, initDatas } = this.props.wfAgentStore;
                            const { listViewPage_listsotre14, listViewPage_listsotre23 } = initDatas
                            let listViewPage_listsotre = this.getlistViewPage_listsotre();
                            listViewPage_listsotre.setState({ selectedRowKeys: [] })
                            setInitDatas({ isShowCheck: false, isSelectedAll: false })

                        }}>{getLabel(201, "取消")}</span>
                        <span>{getLabel(500274, "已选择") + " " + listViewPage_listsotre.selectedRowKeys.length + " " + getLabel(18256, "条")}</span>
                    </div>}

                    {(location.pathname === "/agent/mineAgentSet" || location.pathname === "/agent/all") && this.getListDom1(location.pathname)}
                    {(location.pathname === "/agent/hadAgented" || location.pathname === "/agent/toOthersAgent") && this.getListDom2(location.pathname)}

                    {isShowCheck && this.getGroupButton()}
                </div>

                <Route
                    key={layout_batchEdit.id}
                    path={layout_batchEdit.path}
                    render={() => (
                        <RouteLayout>
                            <div
                                key="wmPoutePageDemo"
                                className="wm-route-layout wm-demo-route-layout-page"
                            >
                                <BatcgEdit />
                            </div>
                        </RouteLayout>
                    )}
                />

            </div>
        );
    }
}


